<template>
  <div class="page-style">
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="品牌LOGO">
        <el-upload
          class="avatar-uploader"
          :action="uploadUrl + '/oss_upload'"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
        >
          <img v-if="form.brand_logo" :src="form.brand_logo" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon" />
        </el-upload>
      </el-form-item>
      <el-form-item label="品牌官方网站">
        <el-input v-model="form.brand_web_url" />
      </el-form-item>
      <el-form-item label="咨询热线">
        <el-input v-model="form.brand_phone" />
      </el-form-item>
      <el-form-item label="公司简介">
        <tinymce v-model="form.brand_text" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">立即提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import tinymce from '@/components/Tinymce'
import { operationBrand, getBrandInfo } from '@/api/brand'
export default {
  components: {
    tinymce
  },
  data() {
    return {
      uploadUrl: process.env.VUE_APP_BASE_API,
      form: {
        id: this.$store.state.user.brand_id,
        brand_web_url: '',
        brand_phone: '',
        brand_text: '',
        brand_logo: ''
      }
    }
  },
  created() {
    // console.log(' 1 ', this.$store.state.user.brand_id)
    this.getBrandInfoFun()
  },
  methods: {
    handleAvatarSuccess(res, file) {
      this.form.brand_logo = res
    },
    uploadData() {
      console.log(this.content)
    },
    getBrandInfoFun() {
      const data = {
        id: this.$store.state.user.brand_id
      }
      getBrandInfo(data).then(res => {
        console.log(res)
        if (res) {
          this.form.brand_web_url = res.brand_web_url
          this.form.brand_phone = res.brand_phone
          this.form.brand_text = res.brand_text
          this.form.brand_logo = res.brand_logo
        }
      })
    },
    submitForm() {
      const data = {
        type: 2,
        pro: this.form
      }
      operationBrand(data).then(res => {
        console.log(res)
        if (res.code === 200) {
          this.$message.success('信息提交成功！')
        }
      })
    }
  }
}
</script>

<style scoped>
 .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 120px;
    height: 120px;
    line-height: 120px;
    text-align: center;
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
  }
  .avatar {
    width: 120px;
    height: 120px;
    display: block;
  }
</style>
